package com.chao.juc.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author : Rookie
 * @description : 启动callable
 * @date : 2022/1/22
 */
public class CallableTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyThread myThread = new MyThread();
        FutureTask task = new FutureTask(myThread);
        new Thread(task,"A").start();
        //结果会缓存
        new Thread(task,"B").start();

        String desc = (String) task.get();
        System.out.println(desc);
    }
}

class MyThread implements Callable<String> {

    @Override
    public String call() throws Exception {
        System.out.println("调用了call方法");
        return "hello";
    }
}
